﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using Models;
using BLL;
using System.Data.Entity;

namespace CMS项目.Areas.HouTaiArea.Controllers
{
    public class CategoryController : Controller
    {
        //全部查询
        BLL_CMS_Category BLL_CMS_Category=new BLL_CMS_Category();
        public ActionResult CMS_Category()
        {
            return View(BLL_CMS_Category.seleAll_CMS_Category());
        }

        [HttpGet]
        // GET: HouTaiArea/Category
        public ActionResult Add()
        {
            return View();
        }
        //添加
        [HttpPost]
        public ActionResult Add(CMS_Category Category)
        {
            int st = BLL_CMS_Category.Insert(Category);
            if (st>0) {
                return Content("<script>alert('保存成功');window.location.href='/HouTaiArea/Category/index';</script>");
            }   
            else
            {
                return Content("<script>alert('保存失败');window.location.href='/HouTaiArea/CMS_User/Index';</script>");
            }


        }
        //删除
            public ActionResult Delete(int id)
            {
            int st = BLL_CMS_Category.Datete(id);
               
                if (st> 0)
                {
                return Content("<script>alert('删除成功');window.location.href='/HouTaiArea/Category/index';</script>");
            }
                else
                {
                return Content("<script>alert('删除失败');window.location.href='/HouTaiArea/CMS_User/Index';</script>");
            }
               
            }
        //单值查询
        public ActionResult Update(int id)
        {
            List<CMS_Category> li =BLL_CMS_Category.Selectid (id);
            return View(li);
        }
        //修改
        public ActionResult Update_Category(int cid, string ctitle, string cname, bool nav, int navorder, bool search)
        {
            int st = BLL_CMS_Category.update_CMS_Category(cid, ctitle, cname, nav, navorder, search);
            if (st > 0)
            {
                return Content("<script>alert('修改成功');window.location.href='/HouTaiArea/Category/index';</script>");
            }
            else
            {
                return Content("<script>alert('修改失败');window.location.href='/HouTaiArea/CMS_User/Index';</script>");
            }
        }
        public ActionResult index() 
        {
            return View();
        
        }
        //分页
        [HttpGet]
        public ActionResult SelectPage(int? pageindex, int? pagesize)
        {
            return Json(BLL_CMS_Category.GetPageCMS_Articles((int)pageindex, (int)pagesize, null), JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public ActionResult SelectPage(int? pageindex, int? pagesize, string cid)
        {
            return Json(BLL_CMS_Category.GetPageCMS_Articles((int)pageindex, (int)pagesize, cid));
        }
    }
}
